import getpass

userdb = {}

def register():
    uname = input('username:')
    if uname in userdb:
        print('%s already exists.' % uname)
    else:
        password = input('password:')
        userdb[uname] = password

def login():
    uname = input('username:')
    password = getpass.getpass('password:')
    if userdb.get(uname) != password:
        print('login failed')
    else:
        print('login successful')

def show_menu():
    cmds = {'0': register, '1': login}
    prompt = '''(0) register
(1) login
(2) exit
Please input your choice(0/1/2):'''

    while True:
        choice = input(prompt).strip()[0]
        if choice not in '012':
            print('Invalid input, Please retry.')
            continue

        if choice == '2':
            print('Bye-bye')
            break

        cmds[choice]()

if __name__ == '__main__':
    show_menu()